package com.authen.utils;

import android.os.Build;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;


public class LedUtil {
	private static void setGPIOStatus(String path, boolean status) {
		String dataOn = "1\n";
		String dataOff = "0\n";
		try {
			File file = new File(path);
			OutputStream out = new FileOutputStream(file);
			if (status) {
				out.write(dataOn.getBytes());
			} else {
				out.write(dataOff.getBytes());
			}
			out.close();
		} catch (IOException e) {
		}
	}
	
	public static void lockOnOff(boolean on) {
		if (Build.MODEL.equals("giktech")) {
			setGPIOStatus("/sys/class/rk29-keypad/gpio0", on);
			setGPIOStatus("/sys/class/rk29-keypad/gpio1", on);
		}
	}
	
	public static void ledOff() {
		if (Build.MODEL.equals("giktech")) {
			setGPIOStatus("/sys/class/rk29-keypad/gpio2", false);
		} else if (Build.MODEL.startsWith("3Q-M")) {
			setGPIOStatus("/sys/bus/platform/drivers/ledlight/ledlight.33/ledlight", false);
			setGPIOStatus("/sys/bus/platform/drivers/ledlight/ledlight.33/ledlight1", false);
			setGPIOStatus("/sys/bus/platform/drivers/ledlight/ledlight.34/ledlight", false);
			setGPIOStatus("/sys/bus/platform/drivers/ledlight/ledlight.34/ledlight1", false);
			setGPIOStatus("/sys/ledlight/ledlight", false);
			setGPIOStatus("/sys/ledlight/ledlight1", false);
		}
	}
	
	public static void ledOn() {
		if (Build.MODEL.equals("giktech")) {
			setGPIOStatus("/sys/class/rk29-keypad/gpio2", true);
		} else if (Build.MODEL.startsWith("3Q-M")) {
			setGPIOStatus("/sys/bus/platform/drivers/ledlight/ledlight.33/ledlight", true);
			setGPIOStatus("/sys/bus/platform/drivers/ledlight/ledlight.33/ledlight1", true);
			setGPIOStatus("/sys/bus/platform/drivers/ledlight/ledlight.34/ledlight", true);
			setGPIOStatus("/sys/bus/platform/drivers/ledlight/ledlight.34/ledlight1", true);
			setGPIOStatus("/sys/ledlight/ledlight", true);
			setGPIOStatus("/sys/ledlight/ledlight1", true);
		}
	}
}
